package com.img2base64;

/**
 * 图片转base64
 *
 * @author zhanghuibo
 * @version 1.0.0
 * @package com.img2base64
 * @className Img2Base64
 * @date 2025-03-28  10:51
 */

import cn.hutool.core.img.ImgUtil;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * @Description
 * @create 2023-03-31 9:55
 */
public class Img2Base64 {
    public static void main(String[] args) throws Exception{

        //本地图片
        String path = "/Users/zhanghuibo/Downloads/_slices/组 57-3.jpg";
        //转换流
        BufferedImage read = ImageIO.read(new File(path));
        //转换base64
        String jpeg = ImgUtil.toBase64(read, "jpeg");
        System.out.println("data:image/jpeg;base64,"+jpeg);
    }
}
